﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Facade;
using IronOne.SalesOne.BusinessObjects;
using IronOne.SalesOne.SalesOneWeb;

namespace IronOne.SalesOne.SalesOneWeb.Collection
{
    public partial class TransactionRemarkDetails : SOSecurityPage
    {
        string SOCode;
        string RecNo;
        string ContrNo;
        string CSSNo;
        StructureFacade facade;
        FinanceFacade finFacad;
        int userType;

        protected void Page_Load(object sender, EventArgs e)
        {
            //Get Query String data
            SOCode = Request.QueryString["SOCode"].ToString();
            RecNo = Request.QueryString["RecNo"].ToString();
            ContrNo = Request.QueryString["ContNo"].ToString();
            finFacad = new FinanceFacade();

            if (!Page.IsPostBack)
            {
                facade = new StructureFacade();

                ValidateUserCredentials(Request.Url.LocalPath);

                User user = facade.GetUser(User.Identity.Name);
                //User user = facade.GetUser("ss");
                UserInformation info = facade.GetUserInformation(User.Identity.Name);
                userType = info.UserType;
                FillTextAreas(info);
            }

            

            

            lblContractNo.Text = ContrNo;
            lblReceiptNumber.Text = RecNo;

        }

        private void FillTextAreas(UserInformation i)
        { 

            List<CollectionTransaction> collRemarks = finFacad.GetRemarks(SOCode, Convert.ToInt64(RecNo));
            txtCashierRemark.Text = collRemarks[0].RemarksCashier;
            txtOtherRemark.Text = collRemarks[0].RemarksSO;
            //txtChangeLog.Text = collRemarks[0].ChangeLog;
            
            //Suren - 2012-05-04
            //Put this new line below and commented the above line.
            //txtChangeLog.Text = "Remark:\n" + collRemarks[0].RemarksSO + "\nReason:\n" + collRemarks[0].Reason;
            txtChangeLog.Text = collRemarks[0].Reason;
            txtChangeLog.Wrap = true;

            /*if (i.BranchId == null || i.UnitId != null)
            {
                txtCashierRemark.ReadOnly = true;
                btnUpdate.Visible = false;
            }*/
            
        }

        protected void TextBox2_TextChanged(object sender, EventArgs e)
        {

        }

        protected void TextBox3_TextChanged(object sender, EventArgs e)
        {

        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Collection/VerifyCollectionTransactionDetails.aspx");
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            //Response.Redirect("~/Collection/SearchVerifyCollectionTransaction.aspx");
            int res = finFacad.UpdateCahierRemarks(SOCode, Convert.ToInt64(RecNo), txtCashierRemark.Text,User.Identity.Name);
            if (res == 1)
            {
                MassageSummery("IIS402");
            }
        }
    }
}
